package guda.house.biz.impl;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;

import guda.house.biz.RenderBiz;
import guda.house.dal.dao.RenderDAO;
import guda.house.dal.dataobject.RenderDO;
import guda.grape.autogen.common.page.BaseQuery;
import guda.grape.autogen.common.page.BizResult;

public class RenderBizImpl implements RenderBiz{

    private final static Logger logger = LoggerFactory.getLogger(RenderBizImpl.class);

    @Autowired
    private RenderDAO renderDAO;

    public BizResult detail(long id) {
        BizResult bizResult = new BizResult();
        try{
            RenderDO renderDO = renderDAO.getRenderById(id);
            bizResult.data.put("renderDO", renderDO);
            bizResult.success = true;
        }catch(Exception e){
            logger.error("query Render error",e);
        }
        return bizResult;
}

    public BizResult list(BaseQuery baseQuery) {
        BizResult bizResult = new BizResult();
        try {
            int totalCount = renderDAO.countForPage(baseQuery);
            baseQuery.setTotalCount(totalCount);
            List<RenderDO> renderList = renderDAO.selectForPage(baseQuery);
            bizResult.data.put("renderList", renderList);
            bizResult.data.put("query", baseQuery);
            bizResult.success = true;
        } catch (Exception e) {
            logger.error("view Render list error", e);
        }
            return bizResult;
     }

    public BizResult delete(long id) {
        BizResult bizResult = new BizResult();
        try {
            renderDAO.delRenderById(id);
            bizResult.success = true;
        } catch (Exception e) {
            logger.error("delete render error", e);
        }
        return bizResult;
    }

    public BizResult create(RenderDO renderDO) {
        BizResult bizResult = new BizResult();
        try {
            long id = renderDAO.insert(renderDO);
            bizResult.data.put("id", id);
            bizResult.success = true;
        } catch (Exception e) {
            logger.error("create Render error", e);
        }
        return bizResult;
    }

    @Override
    public BizResult update(RenderDO renderDO) {
        BizResult bizResult = new BizResult();
        try {
            renderDAO.updateByIdSelective(renderDO);
            bizResult.success = true;
        } catch (Exception e) {
            logger.error("update Render error", e);
        }
        return bizResult;
    }


}
